<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>对账导出</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<link rel="stylesheet" href="css/Inputstyle.css" type="text/css"></link>
<link rel="stylesheet" href="css/mshop.css" type="text/css"></link>
<link rel="stylesheet" href="${ctx}/assets/css/jquery-ui.min.css"
	type="text/css"></link>
<link rel="stylesheet" href="${ctx}/assets/css/jquery-ui.theme.min.css"
	type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
<script type="text/javascript" charset="utf-8"
	src="${ctx }/calender/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/js/jquery-ui.min.js"></script>
<style>
.ui-widget {
	margin-bottom: 10px;
	margin-left: 5px;
}
</style>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>对账导出</li>
						</ul>
						<!-- .breadcrumb -->
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div align="center">
									<div class="common">
										<label>选择企业:&nbsp;</label> <select id="eaStore">
											<option value="-1">-- 自己填写 --</option>
											<option value="0">-- 所有企业 --</option>
											<c:forEach items="${accounts }" var="account">
												<option value="${account.id }">${account.name }</option>
											</c:forEach>
										</select>
									</div>
									<div class="ui-widget">
									<label for="accountName">企业名称:&nbsp;&nbsp;&nbsp;</label>
										 <input
											type="text" class="input" id="accountName"
											style="margin-left:-1px;">
									</div>
									<div class="common">
										<label>固定时间:&nbsp;</label> <label> <select
											id="balTime">
												<option value="0">-- 未选择 --</option>
												<option value="1">本年</option>
												<option value="2">本月</option>
												<option value="3">本周</option>
												<option value="4">今日</option>
										</select> </label>
									</div>
									<div class="common" id="beginTimeDiv">
										<label>开始时间:&nbsp;</label> <input type="text"
											id="balBeginTime" class="Wdate"
											onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
											style="width:180px;height:30px;" placeholder="开始时间">
									</div>
									<div class="common" id="endTimeDiv">
										<label>结束时间:&nbsp;</label> <input type="text" id="balEndTime"
											class="Wdate"
											onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
											style="width:180px;height:30px;" placeholder="结束时间">
									</div>
									<div id="btn-team">
										<input type="button" class="btn btn-primary radius"
											id=exportCSVBtn value="导出" />
									</div>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>

	<script type="text/javascript">
	$(document).ready(function() {
		function selectedTimeShow() {
			if ($("#balTime").val() == 0) {
				$("#beginTimeDiv").show();
				$("#endTimeDiv").show();
			}else {
				$("#beginTimeDiv").hide();
				$("#endTimeDiv").hide();
			}
		}
		
		$("#balTime").change(function() {
			selectedTimeShow();
		});
		
		$("#eaStore").change(function() {
			if ($("#eaStore").val() != -1) {
				$("#accountName").val('');
				$(".ui-widget").hide();
			}else {
				$("#accountName").val('');
				$(".ui-widget").show();
			}
		});
		
		$("#exportCSVBtn").click(function() {
			var url = "mbalance!exportSuperAdminBalanceCSV";
			
			url += "?balance.eaId=" + $("#eaStore").val();
			url += "&balance.timeType=" + $("#balTime").val();
			
			var beginTime = $("#balBeginTime").val();
			var endTime = $("#balEndTime").val();
			// 检查时间区间大小
			if (beginTime != null && beginTime != '' && endTime != null && endTime != '') {
				var startTime = new Date(beginTime.replace("-", "/").replace("-", "/"));
				var overTime = new Date(endTime.replace("-", "/").replace("-", "/"));
				if (startTime >= overTime) {
					alert("起始时间不能大于结束时间");
					return false;
				}
			}
			
			url += "&balance.beginTime=" + beginTime;
			url += "&balance.endTime=" + endTime;
			
			var eaName = $("#accountName").val();
			if ($("#eaStore").val() == -1) {
				if (eaName.length == 0) {
					alert("请输入企业名称");
					return false;
				}else {
					url += "&balance.eaName=" + eaName;
				}
			}
			
			
			window.location.href = url;
		});
		
		$("#accountName").autocomplete({
			minLength:1, //至少得有1个字符才能触发自动匹配的动作
			source: function( request, response ) {
				// request对象只有一个term属性，对应用户输入的文本
				// response是一个函数，在你自行处理并获取数据后，将JSON数据交给该函数处理，以便于autocomplete根据数据显示列表
				$.ajax({
					type: "POST",
		          	url: "maccount!searchAccountNameAuto",
		          	dataType: "json",
		          	data: {
		          		accountName: request.term
			        },
		          	error: function () {
                      alert("异步请求失败");
                  	},
		          	success: function (data) {
		          		var data=$.parseJSON(data);// 表示处理后的JSON数据
                      	response($.map(data, function (item) {
                           return { value: item };
                    	}));// 最后将数据交给autocomplete去展示
                 	}
				});
			}
		});

		$('.chongzhiduizhang > a').css("color", "red");
		selectedTimeShow();
	});
	</script>
</body>
</html>